package com.blog.mapper;

import com.blog.dto.CategoryDTO;
import com.blog.entity.Category;
import com.blog.vo.CategoryVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @Select("select * from tb_category")
    List<Category> select();


    List<Category> selectBatchIds(List<Long> categoryList);


    //加入这个参数@Param("categoryList")，所以在XML文件中能通过categoryList识别使用
    List<Category> selectBatchIdsAndName(@Param("categoryList") List<Long> categoryList,@Param("value") String value);

    @Select("select * from tb_category where id = #{id}")
    Category selectById(@Param("id")Long id);


    void InsertCategory(Category category);

    @Select("select * from tb_category where type = #{upperValue}")
    Category selectByName(String upperValue);

    @Update("update tb_category set type = #{type} where id = #{id}")

    void update(CategoryDTO categoryDTO);
    @Select("SELECT *  FROM tb_category WHERE id in (SELECT category_id FROM tb_user_category WHERE user_id = #{uid})")
    List<CategoryVO> selectCategoryList(@Param("uid") Long uid);

    @Select("select count(*)t from tb_category_article where category_ID = #{cid}")
    Long countArticle(@Param("cid") Long cid);
}
